package com.bullsora.kindlerss.model;

import com.googlecode.objectify.annotation.Cached;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author sorin.buliarca@iquesint.com
 */
@Entity
@Cached
public class Subscription {

  @Id
  private Long id;

  private String prefix;

  private Date lastChecked;

  private Long userId;

  private String sendCronExpression;

  private Date nextCheck;


  @Embedded
  private List<Feed> feeds = new ArrayList<Feed>();

  @Transient
  private List<Feed> nonEmptyFeeds;

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }


  public Date getNextCheck() {
    return nextCheck;
  }

  public void setNextCheck(Date nextCheck) {
    this.nextCheck = nextCheck;
  }

  public String getSendCronExpression() {
    return sendCronExpression;
  }

  public void setSendCronExpression(String sendCronExpression) {
    this.sendCronExpression = sendCronExpression;
  }

  public String getPrefix() {
    return prefix;
  }

  public void setPrefix(String prefix) {
    this.prefix = prefix;
  }

  public Date getLastChecked() {
    return lastChecked;
  }

  public void setLastChecked(Date lastChecked) {
    this.lastChecked = lastChecked;
  }


  public Long getUserId() {
    return userId;
  }

  public void setUserId(Long userId) {
    this.userId = userId;
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    Subscription that = (Subscription) o;

    if (id != null ? !id.equals(that.id) : that.id != null) return false;

    return true;
  }

  @Override
  public int hashCode() {
    return id != null ? id.hashCode() : 0;
  }

  public List<Feed> getFeeds() {
    return feeds;
  }

  public void setFeeds(List<Feed> feeds) {
    this.feeds = feeds;
  }

  public List<Feed> getNonEmptyFeeds() {
    return nonEmptyFeeds;
  }

  public void setNonEmptyFeeds(List<Feed> nonEmptyFeeds) {
    this.nonEmptyFeeds = nonEmptyFeeds;
  }
}
